package com.aop;

/**
 * @Author Fizz Pu
 * @Date 2021/5/3 下午9:30
 * @Version 1.0
 * 失之毫厘，缪之千里！
 */

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

// 切面类
@Aspect
@Component
public class AopAspect {
    @Pointcut("execution(* com.aop.AopStrengthen.*(..))")
    public void pointcut() {
    }

    @Before("pointcut()")
    public void beforeAdvice(){
        System.out.println("before");
    }

    @After("pointcut()")
    public void afterAdvice(JoinPoint joinPoint){
        System.out.println("参数长度=" + joinPoint.getArgs().length);
        System.out.println("after");
    }

    @AfterThrowing(pointcut = "pointcut()", throwing = "ex")
    public void afterThrowing(Exception ex){
        System.out.println("exception" + ex);
    }

    @AfterReturning(pointcut = "pointcut()", returning = "returnVal")
    public void afterReturning(Object returnVal){
        System.out.println("afterReturning" + returnVal);
    }

    @Around("pointcut()")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("around start...");
        joinPoint.proceed();
        System.out.println("around end...");
    }
}
